1 package mobisnap.mobile_trx; 2 3 import java.util.*; 4 5 public class MSQLNames 6 { 7 Vector names; 8 9 public MSQLNames() { 10 names = new Vector(); 11 12 inScope(); 13 try { 14 newFunction( "notify", new MSQLTFunNotify()); 15 newFunction( "print", new MSQLTFunPrint()); 16 } catch( Exception e) { 17 // do nothing 18 } 19 } 20 21 /*** 22 * Reset names 23 */ 24 public void reset() { 25 names.removeAllElements(); 26 27 inScope(); 28 try { 29 newFunction( "notify", new MSQLTFunNotify()); 30 newFunction( "print", new MSQLTFunPrint()); 31 } catch( Exception e) { 32 // do nothing 33 } 34 } 35 36 /*** 37 * The code execution has entered a new scope 38 */ 39 public void inScope() { 40 names.addElement( new Hashtable()); 41 } 42 43 /*** 44 * The code execution has exited a new scope - all names declared in this 45 * scope should be removed 46 */ 47 public void outScope() { 48 if( names.size() > 0) 49 names.removeElementAt( names.size() - 1); 50 } 51 52 /*** 53 * Returns the variable that represents the given name 54 */ 55 public MSQLTName getName( String name) 56 throws Exception { 57 for( int i = names.size() - 1 ; i >= 0 ; i--) { 58 Hashtable table = (Hashtable)names.elementAt(i); 59 Object obj = table.get( name); 60 if( obj != null) 61 return (MSQLTName)obj; 62 } 63 throw new mobisnap.MobisnapException( "Name :" + name + ": not found."); 64 } 65 66 /*** 67 * Returns the function that represents the given name with the given parameters 68 */ 69 public MSQLTName getName( String name, Object[] params) 70 throws Exception { 71 return getName( name); 72 } 73 74 /*** 75 * Inserts variable 76 */ 77 public void newVariable( String name, MSQLTVariable obj) 78 throws Exception { 79 if( names.size() == 0) 80 throw new mobisnap.MobisnapException( "newVariable: new name with no scope defined"); 81 Hashtable table = (Hashtable)names.elementAt( names.size() - 1); 82 if( table.get( name) != null) 83 throw new mobisnap.MobisnapException( "newVariable: name already exists"); 84 table.put( name, obj); 85 } 86 87 /*** 88 * Inserts function 89 */ 90 public void newFunction( String name, MSQLTFunction obj) 91 throws Exception { 92 if( names.size() == 0) 93 throw new mobisnap.MobisnapException( "newFunction: new name with no scope defined"); 94 Hashtable table = (Hashtable)names.elementAt( names.size() - 1); 95 if( table.get( name) != null) 96 throw new mobisnap.MobisnapException( "newFunction: name already exists"); 97 table.put( name, obj); 98 } 99 100 public void dump() { 101 Enumeration enum = names.elements(); 102 while( enum.hasMoreElements()) { 103 Hashtable table = (Hashtable)enum.nextElement(); 104 Enumeration enum2 = table.keys(); 105 while( enum2.hasMoreElements()) { 106 String s = (String)enum2.nextElement(); 107 MSQLTName var = (MSQLTName)table.get( s); 108 System.out.println( s + "---->" + var); 109 } 110 } 111 } 112 }

This page was automatically generated by Maven